<template>
	<view class="container">
		<!-- 信息列表 -->
		<view class="content">
			<view v-for="(item,index) in infoListData" :key="index" @click="getListInfoId(item)">
				<view class="sentTimes">
					<text v-if="dateMonthDay == item.sentMonthDay">今天 {{item.sentTime}}
					</text>
					<text v-else-if="item.sentMonthDay == datePrevTwoDay">昨天 {{item.sentTime}}</text>
					<text v-else>{{item.sentDate}}</text>
				</view>
				<view class="info_pre">
					<view class="receiverName">
						{{item.receiverName}}:
					</view>
					<view class="contentTxt">
						{{item.content}}
					</view>
				</view>
			</view>
		</view>
		<!-- 详情信息 -->
		<view class="infoListAll" v-show="isShow">
			<view class="listInfoStyle">
				<view class="receiverNameInfo">
					{{listInfo.receiverName}}:
				</view>
				<view class="contentTxtInfo">
					{{listInfo.content}}
				</view>
				<view class="sponsorName">
					—— {{listInfo.sponsorName}}
				</view>
			</view>
			<view class="imgCancels">
				<image @click="cancels" src="/static/image/Close@2x.png" mode="aspectFit"></image>
			</view>
		</view>

		<!-- 遮罩层 -->
		<view class="mask" v-show="isMask"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// title: '主动关怀',
				infoListData: [],
				listInfo: [],
				userId: '4028d0817abc71bc017abccb8e58006c',
				isMask: false,
				isShow: false
			}
		},
		onLoad() {
			uni.startPullDownRefresh();
			this.getDate();
		},
		onShow() {
			this.getInfoList();
		},
		methods: {
			async getInfoList() {
				const res = await this
					.$myRequest({ //await 关键字 只能放在 async 函数内部， await关键字的作用 就是获取 Promise中返回的内容， 获取的是Promise函数中resolve或者reject的值
						url: '/api-operate/activecare/byReceiver/' + this.userId,
						method: "get",
					})
				if (res.success == true) {
					this.infoListData = res.body.activecare;
					for (let i in this.infoListData) {
						this.infoListData[i].sentMonthDay = null;
						this.infoListData[i].sentTime = null;
						if (this.infoListData[i].sentDate != null) {
							var sentDates = this.infoListData[i].sentDate;
							var timearr = sentDates.replace(" ", ":").replace(/\:/g, "-").split("-");
							this.infoListData[i].sentDate = timearr[1] + "-" + timearr[2] + " " + timearr[3] + ":" +
								timearr[4];
							this.infoListData[i].sentMonthDay = timearr[1] + "-" + timearr[2];
							this.infoListData[i].sentTime = timearr[3] + ":" + timearr[4];
						}
					}
				}
			},
			//-------------------------------------------
			//获取当前时间对比发送时间
			getDate() {
				var date = new Date();
				var month = date.getMonth() + 1,
					day = date.getDate(),
					prevDay = date.getDate() - 1;
				month > 0 && month < 10 ? (month = "0" + month) : '';
				this.dateMonthDay = month + "-" + day;
				this.datePrevTwoDay = month + "-" + prevDay;
			},
			//-----------------------------------------------------
			//下拉刷新
			onPullDownRefresh() {
				setTimeout(() => {
					uni.stopPullDownRefresh();
					this.getInfoList();
				}, 1000);
			},
			//-----------------------------------------------------
			//根据id查看详情信息
			async getListInfoId(item) {
				const res = await this
					.$myRequest({ //await 关键字 只能放在 async 函数内部， await关键字的作用 就是获取 Promise中返回的内容， 获取的是Promise函数中resolve或者reject的值
						url: '/api-operate/activecare/' + item.id,
						method: "get",
					})
				if (res.success == true) {
					this.listInfo = res.body.command;
					this.isMask = true;
					this.isShow = true;
				}
			},
			//---------------------------------------------------
			//取消按钮
			cancels(){
				this.isMask = false;
				this.isShow = false;
			}
			//------------------------------------------------
			//获取当前发送者的id
			// getUserId() {
			// 	this.userId = uni.getStorageSync('id');
			// }
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		height: 100%;

		.content {
			margin-top: 3%;

			.sentTimes {
				text {
					width: 100%;
					display: flex;
					justify-content: center;
					font-size: 32rpx;
					color: #000000;
				}
			}

			.info_pre {
				width: 80%;
				margin: 4% auto;
				border: 1px solid #e1e1e1;
				box-shadow: 1px 1px 10px #9eaeb5;
				background-color: white;
				border-radius: 8px;

				.receiverName {
					width: 76%;
					position: relative;
					left: 20%;
					margin: 3% 0;
					font-size: 32rpx;
					color: #000000;
				}

				.contentTxt {
					width: 76%;
					position: relative;
					left: 20%;
					margin: 3% 0;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					font-size: 32rpx;
					color: #000000;
				}
			}
		}

		//----------------------------------------------
		//详情数据
		.infoListAll {
			position: fixed;
			left: 0;
			right: 0;
			top: 0;
			bottom: 16%;
			margin: auto auto;
			width: 86%;
			height: 700rpx;
			z-index: 99;
			
			//-----------------------------------------------
			//信息详情区
			.listInfoStyle {
				width: 100%;
				height: 500rpx;
				border-radius: 8rpx;
				background-color: #ffffff;
				color: #000000;
				font-size: 32rpx;

				.receiverNameInfo {
					height: 18%;
					display: flex;
					align-items: center;
					padding-left: 4%;

				}

				.contentTxtInfo {
					height: 64%;
					padding: 0 4%;
				}

				.sponsorName {
					height: 18%;
					display: flex;
					align-items: center;
					justify-content: flex-end;
					padding-right: 8%;
				}
			}

			//-----------------------------------------------------
			//取消按钮
			.imgCancels {
				width: 100%;
				height: 200rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				image{
					width: 100rpx;
					height: 100rpx;
				}
			}
		}

		//--------------------------------------------------------------------------------
		//遮罩层
		.mask {
			width: 100%;
			height: 100%;
			position: fixed;
			left: 0;
			bottom: 0;
			z-index: 10;
			background-color: #000;
			opacity: 0.6;
		}
	}
</style>
